#coding=utf-8
#主页panel
#time:20170902
import wx
import  wx.lib.buttons  as  buttons

import wx.py.images as images
#自己的图片
import images as img

import wx.html2

#png图片报错 iCCP: known incorrect sRGB profile  去掉警告

try:
    import agw.flatnotebook as FNB
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.flatnotebook as FNB


from MainPanel import MainPanel
from Purchase import PurchasePanel
from Repertory import RepertoryFrame
from Statement import StatementPanel

wx.Log.SetLogLevel(1)


class MainPage(wx.Frame):
	def __init__(self):
		wx.Frame.__init__(self, None, -1,title=u'安福进销存',style=wx.MINIMIZE_BOX
				|wx.FRAME_SHAPED
				|wx.SIMPLE_BORDER
				# |wx.FRAME_NO_TASKBAR
				# |wx.STAY_ON_TOP
				|wx.SIMPLE_BORDER)

		
		#设置背景颜色
		self.SetBackgroundColour('#ffffff')
		self.isMax = False
		self.SetSize(wx.Size(1100,650))
		self.Center()

		#设置界面
		self.ShowView()
		#绑定事件
		self.BindEvt()

		
		c_x, c_y, c_w, c_h = wx.ClientDisplayRect()
		if c_w<=1024:
			wx.MessageBox(u"呀呀呀，您的屏幕太小啦，只有%s×%s ╮(￣▽￣)╭\
				\n继续使用体验不是很好哦. (=・ω・=)\
				\n建议您更换个大显示器，享受超爽体验(｡･ω･｡)"%(c_w,c_h), u"抱歉！")


		
	#双击事件
	def OnDoubleClick(self,evt):
		pass


	def OnExit(self,evt):
		dlg =  wx.MessageDialog(self,u'确认关闭程序吗？',u'提示',wx.OK|wx.CANCEL)
		if dlg.ShowModal()==wx.ID_OK:
			self.Close()
		dlg.Destroy()

	def OnIconize(self,evt):
		self.Iconize(True)

	#最大化覆盖了任务栏的解决方案
	def OnMaximized(self,evt):
		if self.isMax:
			self.isMax = False
			self.SetSize(wx.Size(1100,650))
			self.Center()
		else:
			self.isMax=True
			c_x, c_y, c_w, c_h = wx.ClientDisplayRect()
			self.SetSize(wx.Size(c_w,c_h))
			self.SetPosition(wx.Point(0,0))
		# self.Refresh()


	#鼠标按下
	def OnLeftDown(self,evt):
		self.CaptureMouse()
		pos = self.ClientToScreen(evt.GetPosition())
		origin = self.GetPosition()
		self.delta = wx.Point(pos.x - origin.x,pos.y - origin.y)

	#鼠标移动
	def OnMouseMove(self,evt):
		if evt.Dragging() and evt.LeftIsDown():
			pos = self.ClientToScreen(evt.GetPosition())
			newPos = (pos.x - self.delta.x, pos.y - self.delta.y)
			self.Move(newPos)


	#鼠标释放
	def OnLeftUp(self,evt):
		if self.HasCapture():
			self.ReleaseMouse()

	#主界面布局图
	def ShowView(self):
		#拖动没有标题的框架
		self.hasShape = False
		self.delta = wx.Point(0,0)

		self.p1 = wx.Panel(self,-1)
		self.p1.SetBackgroundColour('#029be2')
		#面板2  
		self.p2 = wx.Panel(self,-1)
		self.p2.SetBackgroundColour('white')

		self.p3 = wx.Panel(self,-1)
		self.p3.SetBackgroundColour('red')

		#左侧图标按钮
		self.LeftView()
		#顶部
		self.RightTopView()



		kucunText = wx.StaticText(self,-1,u'  库存查询 ')
		nulltext = wx.StaticText(self,-1,u'  ',size=(300,1))
		kucunText.SetFont(wx.Font(12,wx.DEFAULT, wx.NORMAL, wx.BOLD))
		kucunText.SetForegroundColour('#5f6b7a')
		self.search = wx.SearchCtrl(self,size=(250,30),style=wx.TE_PROCESS_ENTER)
		self.search.SetDescriptiveText(u'输入商品编码或关键字进行搜索')
		self.search.SetBackgroundColour('#e7ecef')
		self.search.SetFocus()  #获得焦点

		
		#关闭按钮
		b = wx.Image('images/sale/close_default.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight()+0)
		self.ClosePng = wx.StaticBitmap(self,-1,wx.Bitmap(b),size=(b.GetWidth(),b.GetHeight()))
		folist = 'images/sale/close_across.png'
		olist = 'images/sale/close_default.png'
		self.ClosePng.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.ClosePng,folist]: self.OnEnter(evt,mark))
		self.ClosePng.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.ClosePng,olist]: self.OnLeave(evt,mark))
		self.ClosePng.Bind(wx.EVT_LEFT_DOWN,self.OnExit)
		#最大化按钮
		b = wx.Image('images/sale/max_default.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight()+0)
		self.maxPng = wx.StaticBitmap(self,-1,wx.Bitmap(b),size=(b.GetWidth(),b.GetHeight()))
		folist = 'images/sale/max_across.png'
		olist = 'images/sale/max_default.png'
		self.maxPng.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.maxPng,folist]: self.OnEnter(evt,mark))
		self.maxPng.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.maxPng,olist]: self.OnLeave(evt,mark))
		self.maxPng.Bind(wx.EVT_LEFT_DOWN,self.OnMaximized)
		#最小化按钮
		b = wx.Image('images/sale/min_default.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight()+0)
		self.minPng = wx.StaticBitmap(self,-1,wx.Bitmap(b),size=(b.GetWidth(),b.GetHeight()))
		folist = 'images/sale/min_across.png'
		olist = 'images/sale/min_default.png'
		self.minPng.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.minPng,folist]: self.OnEnter(evt,mark))
		self.minPng.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.minPng,olist]: self.OnLeave(evt,mark))
		self.minPng.Bind(wx.EVT_LEFT_DOWN,self.OnIconize)

		self.textQQ = wx.StaticText(self,-1,u'QQ咨询:666666 ')
		self.textQQ.SetForegroundColour('#67737c')
		#右上角帮助按钮
		b = wx.Image('images/sale/help_default.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight()+0)
		self.helpPng = wx.StaticBitmap(self,-1,wx.Bitmap(b),size=(b.GetWidth(),b.GetHeight()))
		folist = 'images/sale/help_across.png'
		olist = 'images/sale/help_default.png'
		self.helpPng.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.helpPng,folist]: self.OnEnter(evt,mark))
		self.helpPng.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.helpPng,olist]: self.OnLeave(evt,mark))


		#主sizer
		mainSizer = wx.GridBagSizer()
		mainSizer.Add(self.p1, pos=(0,0),span=(2,1) ,flag=wx.EXPAND)
		shu1text = wx.StaticText(self,-1,u'|')
		shu1text.SetForegroundColour('#cacaca')
		shu2text = wx.StaticText(self,-1,u'|')
		shu2text.SetForegroundColour('#cacaca')
		shu3text = wx.StaticText(self,-1,u' | ')
		shu3text.SetForegroundColour('#cacaca')
		shu4text = wx.StaticText(self,-1,u' | ')
		shu4text.SetForegroundColour('#cacaca')

		self.edition = wx.StaticText(self,-1,u'[免费版]')
		self.edition.SetForegroundColour('#67737c')

		self.Updateedition = wx.StaticText(self,-1,u'升级会员版解锁更多姿势哟')
		self.Updateedition.SetForegroundColour('red')
		
		#右上 左右
		RightTopSizer = wx.GridBagSizer()
		RightTopSizer.Add(kucunText,pos=(0,0),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(self.search,pos=(0,1),flag=wx.ALIGN_CENTER)

		RightTopSizer.Add(self.edition,pos=(0,3),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(shu4text,pos=(0,4),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(self.Updateedition,pos=(0,5),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(shu3text,pos=(0,6),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(self.textQQ,pos=(0,7),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(shu2text,pos=(0,8),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(self.helpPng,pos=(0,9),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(shu1text,pos=(0,10),flag=wx.ALIGN_RIGHT|wx.ALIGN_CENTER)
		RightTopSizer.Add(self.minPng,pos=(0,11),flag=wx.ALIGN_RIGHT)
		RightTopSizer.Add(self.maxPng,pos=(0,12),flag=wx.ALIGN_RIGHT)
		RightTopSizer.Add(self.ClosePng,pos=(0,13),flag=wx.ALIGN_RIGHT)
		RightTopSizer.AddGrowableCol(2)

		#右上
		mainSizer.Add(RightTopSizer, pos=(0,1), flag=wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)

		#右下上
		self.srt = wx.BoxSizer(wx.VERTICAL)
		#右下下
		
		# self.prt = wx.Panel(self,-1,size=(800,50),style=wx.BORDER_STATIC)
		# self.OnMainRightBottomTopPanelView()

		# b = wx.Image('images/main/ooopic_1504429478.png',wx.BITMAP_TYPE_PNG)
		# b = b.Scale(32,32)
		# mainBannerLogoImg = wx.StaticBitmap(self.prt,-1,wx.Bitmap(b),pos=(10,10))

		# line = wx.StaticLine(self.prt,-1,size=(2000,2),pos=(0,0))
		# help(line)
		# line.SetForegroundColour('red')
		# line1 = wx.StaticLine(self.prt,-1,size=(2000,2),pos=(0,49))
		# line1.SetForegroundColour('red')

		# logoText = wx.StaticText(self.prt,-1,u'福安进销存[免费版]',pos=(50,15))
		# logoText.SetForegroundColour('#67737c')
		# logoText.SetFont(wx.Font(16,wx.DEFAULT, wx.NORMAL, wx.BOLD))

		# self.RightPanel = wx.Panel(self.prt,-1,size=(80,50),pos=(270,1))
		# self.RightPanel.SetBackgroundColour('#029be2')
		# self.shouye = wx.StaticText(self.RightPanel,-1,u'首 页',pos=(15,15))
		# self.shouye.SetForegroundColour('#ffffff')
		# self.shouye.SetFont(wx.Font(14,wx.DEFAULT, wx.NORMAL, wx.BOLD))

		# self.srt.Add(self.prt, flag=wx.EXPAND)

		bookStyle = FNB.FNB_BOTTOM \
			|FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS \
			# |FNB.FNB_HIDE_TABS \
			# |FNB.FNB_NODRAG \

		self.book = FNB.FlatNotebook(self, wx.ID_ANY, agwStyle=0)
		#这里设置不生效。
		#要进源码里面设置  第一个参数  204行FNB_HEIGHT_SPACER   默认=10
		# self.book.FNB_HEIGHT_SPACER = 50
		#主面板

		# self.srt.Add(MainPanel(self),1,flag=wx.EXPAND)
		# self.book.SetTabCtrlHeight(50)
		self.srt.Add(self.book,1,flag=wx.EXPAND)
		p1 = MainPanel(self)

		# self.book.AddPage(logoText,u'111dafda', True)
		self.book.AddPage(p1,u'  主页  ', True)
		# self.book.SetCustomPage(self.p3)
		# self.book.GetTextExtent()
		# self.book.SetFont(wx.Font(16,wx.DEFAULT,wx.NORMAL, wx.BOLD))

		mainSizer.Add(self.srt, pos=(1,1),flag=wx.EXPAND)

		mainSizer.AddGrowableCol(1)
		mainSizer.AddGrowableRow(1,1)

		
		self.SetSizer(mainSizer)
		
		self.Fit()
		mainSizer.SetSizeHints(self)

	# def OnMainRightBottomTopPanelView(self):
	# 	self.prt.SetBackgroundColour('#fafafa')



	#事件绑定
	def BindEvt(self):
		#双击事件
		# self.Bind(wx.EVT_LEFT_DCLICK,self.OnDoubleClick)
		#拖动窗口
		self.Bind(wx.EVT_LEFT_DOWN,self.OnLeftDown)
		self.Bind(wx.EVT_LEFT_UP,self.OnLeftUp)
		self.Bind(wx.EVT_MOTION,self.OnMouseMove)
		#book 窗口发生改变
		self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
		#关闭窗口
		# self.Bind(wx.EVT_RIGHT_UP,self.OnExit)

	def RightTopView(self):pass

	def OnPageChanging(self, event):
		old = event.GetOldSelection()
		now = event.GetSelection()

	#添加面板
	def OnLeftSelectDown(self,evt,*args):
		self.book.AddPage(args[0][1],args[0][0], True)

	#左边窗口
	def LeftView(self):

		#logo
		b = wx.Image('images/logo.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight())
		self.logo = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,0))
		folist = 'images/logo-huaguo.png'
		olist = 'images/logo.png'
		self.logo.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.logo,folist]: self.OnEnter(evt,mark))
		self.logo.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.logo,olist]: self.OnLeave(evt,mark))


		#进货
		b = wx.Image('images/fin.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight())
		self.fin = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,90))
		folist = 'images/fin-huaguo.png'
		olist = 'images/fin.png'
		self.fin.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.fin,folist]: self.OnEnter(evt,mark))
		self.fin.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.fin,olist]: self.OnLeave(evt,mark))
		
		self.fin.Bind(wx.EVT_LEFT_DOWN,lambda evt,mark=[u'  采购单  ',PurchasePanel(self)]: self.OnLeftSelectDown(evt,mark))

		#出货
		b = wx.Image('images/fout.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight())
		self.fout = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,150))
		folist = 'images/fout-huaguo.png'
		olist = 'images/fout.png'
		self.fout.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.fout,folist]: self.OnEnter(evt,mark))
		self.fout.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.fout,olist]: self.OnLeave(evt,mark))
		# self.fout.Bind(wx.EVT_LEFT_DOWN,lambda evt,mark=[self.fout,u'  采购单  ',u'进货单',self.jinhuodanPanel]: self.OnLeftSelectDown(evt,mark))


		#仓库
		b = wx.Image('images/warehouse.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight())
		self.warehouse = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,210))
		folist = 'images/warehouse-huaguo.png'
		olist = 'images/warehouse.png'
		self.warehouse.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.warehouse,folist]: self.OnEnter(evt,mark))
		self.warehouse.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.warehouse,olist]: self.OnLeave(evt,mark))
		self.warehouse.Bind(wx.EVT_LEFT_DOWN,lambda evt,mark=[u'  库存管理  ',RepertoryFrame(self)]: self.OnLeftSelectDown(evt,mark))

		#资金
		# b = wx.Image('images/capital.png',wx.BITMAP_TYPE_PNG)
		# b = b.Scale(b.GetWidth()+3,b.GetHeight())
		# self.capital = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,270))
		# folist = 'images/capital-huaguo.png'
		# olist = 'images/capital.png'
		# self.capital.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.capital,folist]: self.OnEnter(evt,mark))
		# self.capital.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.capital,olist]: self.OnLeave(evt,mark))

		#报表
		b = wx.Image('images/report.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight())
		self.report = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,270))
		folist = 'images/report-huaguo.png'
		olist = 'images/report.png'
		self.report.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.report,folist]: self.OnEnter(evt,mark))
		self.report.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.report,olist]: self.OnLeave(evt,mark))
		self.report.Bind(wx.EVT_LEFT_DOWN,lambda evt,mark=[u'  报表管理  ',StatementPanel(self)]: self.OnLeftSelectDown(evt,mark))

		#数据
		b = wx.Image('images/infodata.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight())
		self.infodata = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,330))
		folist = 'images/infodata-huaguo.png'
		olist = 'images/infodata.png'
		self.infodata.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.infodata,folist]: self.OnEnter(evt,mark))
		self.infodata.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.infodata,olist]: self.OnLeave(evt,mark))

		#设置
		b = wx.Image('images/setting.png',wx.BITMAP_TYPE_PNG)
		b = b.Scale(b.GetWidth()+3,b.GetHeight())
		self.setting = wx.StaticBitmap(self.p1,-1,wx.Bitmap(b),pos=(0,390))
		folist = 'images/setting-huaguo.png'
		olist = 'images/setting.png'
		self.setting.Bind(wx.EVT_ENTER_WINDOW,lambda evt,mark=[self.setting,folist]: self.OnEnter(evt,mark))
		self.setting.Bind(wx.EVT_LEAVE_WINDOW,lambda evt,mark=[self.setting,olist]: self.OnLeave(evt,mark))


		
	def OnEnter(self,evt,evm):
		try:
			logopng0 = wx.Image(evm[1],wx.BITMAP_TYPE_PNG)
			logopng1 = logopng0.Scale(logopng0.GetWidth()+3,logopng0.GetHeight())
			evm[0].SetBitmap(wx.Bitmap(logopng1))
		except Exception, e:
			print str(e)
		
	
	def OnLeave(self,evt,evm):
		try:
			logopng0 = wx.Image(evm[1],wx.BITMAP_TYPE_PNG)
			logopng1 = logopng0.Scale(logopng0.GetWidth()+3,logopng0.GetHeight())
			evm[0].SetBitmap(wx.Bitmap(logopng1))
		except Exception, e:
			print str(e)
		evt.Skip()
		
		

	def OnLogoLeftUp(self,evt):
		print 'hhh'


if __name__ == '__main__':
	app = wx.PySimpleApp()
	form = MainPage()
	form.Show()
	app.SetTopWindow(form)
	app.MainLoop()